package practice1_100;

import java.util.Arrays;

public class QuickSort {
    public void sort(int[] array) {
        if (array.length <= 1) return;
        quickSort(array, 0, array.length - 1);

    }

    public void quickSort(int[] array, int left, int right) {
        if (right <= left) return;
        int leftOr = left, rightOr = right;
        int temp = array[left];
        while (left < right) {
            while (left < right && array[right] > temp) {//
                right--;
            }
            if (left < right) {
                array[left] = array[right];
                left++;
            }
            while (left < right && array[left] < temp) {
                left++;
            }
            if (left < right) {
                array[right] = array[left];
                right--;
            }
        }
        array[left] = temp;

        quickSort(array, leftOr, left - 1);
        quickSort(array, left + 1, rightOr);

    }

    public static int[]  gennerateArray(int len,int max){
        int[] arr=new int[len];
        for(int i=0;i<arr.length;i++){
            arr[i]=(int)(Math.random()*max)+1;
        }
        return arr;
    }

    public static void main(String[] args) {
       int[] a= gennerateArray(100000000,10000);
        //int[] a = new int[]{4, 5, 3, 2, 6, 52, 62, 6, 54, 7, 4, 255, 7, 48, 48, 25, 8, 4, 8, 10000, 48, 64, 8, 4, 8, 4,4, 5, 3, 2, 6, 52, 62, 6, 54, 7, 4, 255, 7, 48, 48, 25, 8, 4, 8, 10000, 48, 64, 8, 4, 8, 4,4, 5, 3, 2, 6, 52, 62, 6, 54, 7, 4, 255, 7, 48, 48, 25, 8, 4, 8, 10000, 48, 64, 8, 4, 8, 4,4, 5, 3, 2, 6, 52, 62, 6, 54, 7, 4, 255, 7, 48, 48, 25, 8, 4, 8, 10000, 48, 64, 8, 4, 8, 4,4, 5, 3, 2, 6, 52, 62, 6, 54, 7, 4, 255, 7, 48, 48, 25, 8, 4, 8, 10000, 48, 64, 8, 4, 8, 4,4, 5, 3, 2, 6, 52, 62, 6, 54, 7, 4, 255, 7, 48, 48, 25, 8, 4, 8, 10000, 48, 64, 8, 4, 8, 4,4, 5, 3, 2, 6, 52, 62, 6, 54, 7, 4, 255, 7, 48, 48, 25, 8, 4, 8, 10000, 48, 64, 8, 4, 8, 4,4, 5, 3, 2, 6, 52, 62, 6, 54, 7, 4, 255, 7, 48, 48, 25, 8, 4, 8, 10000, 48, 64, 8, 4, 8, 4,4, 5, 3, 2, 6, 52, 62, 6, 54, 7, 4, 255, 7, 48, 48, 25, 8, 4, 8, 10000, 48, 64, 8, 4, 8, 4,4, 5, 3, 2, 6, 52, 62, 6, 54, 7, 4, 255, 7, 48, 48, 25, 8, 4, 8, 10000, 48, 64, 8, 4, 8, 4,4, 5, 3, 2, 6, 52, 62, 6, 54, 7, 4, 255, 7, 48, 48, 25, 8, 4, 8, 10000, 48, 64, 8, 4, 8, 4,4, 5, 3, 2, 6, 52, 62, 6, 54, 7, 4, 255, 7, 48, 48, 25, 8, 4, 8, 10000, 48, 64, 8, 4, 8, 4,4, 5, 3, 2, 6, 52, 62, 6, 54, 7, 4, 255, 7, 48, 48, 25, 8, 4, 8, 10000, 48, 64, 8, 4, 8, 4,4, 5, 3, 2, 6, 52, 62, 6, 54, 7, 4, 255, 7, 48, 48, 25, 8, 4, 8, 10000, 48, 64, 8, 4, 8, 4};
        new QuickSort().sort(a);
        System.out.println(a.toString());

    }
}
